package com.example;

/**
 * @desc:
 * @author: Shoko
 * @date: 2025/6/1
 */
// 关门状态
class DoorClosedState implements ElevatorState {
    private Elevator elevator;

    public DoorClosedState(Elevator elevator) {
        this.elevator = elevator;
    }

    @Override
    public void moveToFloor(int floor) {
        if (floor == elevator.getCurrentFloor()) {
            System.out.println("已经在 " + floor + " 层，无需移动");
            elevator.openDoor();
        } else {
            System.out.println("电梯从 " + elevator.getCurrentFloor() + " 层移动到 " + floor + " 层");
            elevator.setDestinationFloor(floor);
            elevator.changeState(new RunningState(elevator));
        }
    }

    @Override
    public void openDoor() {
        System.out.println("电梯门正在打开");
        elevator.changeState(new DoorOpenState(elevator));
    }

    @Override
    public void closeDoor() {
        System.out.println("电梯门已经关闭");
    }

    @Override
    public void markFault() {
        System.out.println("电梯关门时发生故障，停止运行");
        elevator.changeState(new FaultState(elevator));
    }

    @Override
    public void fixFault() {
        System.out.println("电梯没有故障，无需修复");
    }
}
